#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=3005;
int T,mod,a[N],b[N],f[N][N];
signed main() {
	freopen("moon.in","r",stdin);
	freopen("moon.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>T>>mod;
	a[0]=1;
	for(int i=1;i<N;i++){
		int num=i*2-1;
		for(int j=num;j<=min(N-1,i*i);j++){
			f[i][j]=a[j-num];
		}
		for(int j=0;j<N;j++) a[j]=(a[j]+f[i][j])%mod;
	}
	while(T--){
		int x;cin>>x;
		cout<<a[x]<<'\n';
	}
	return 0;
}
